import Taro from '@tarojs/taro'
import { useMemo } from 'react'
import { useRequest } from 'ahooks'

export function useSystemInfo() {
  const { data: systemInfo, refresh } = useRequest(Taro.getSystemInfo)

  const pixelRatio = useMemo(() => systemInfo?.pixelRatio ?? 1, [systemInfo])
  const windowWidth = useMemo(() => systemInfo?.windowWidth ?? 0, [systemInfo])
  const windowHeight = useMemo(() => systemInfo?.windowHeight ?? 0, [systemInfo])
  const statusBarHeight = useMemo(() => systemInfo?.statusBarHeight ?? 0, [systemInfo])

  return { pixelRatio, windowWidth, windowHeight, statusBarHeight, refresh }
}
